﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Role_Add :BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        UserPower.CheckAction((int)FreeHouse.Power.Actions.TRole.Add);
        if (!IsPostBack) BindData();
    }

    protected void BindData()
    {
        parentRole.DataSource = new FreeHouse.BLL.TRole().GetList("");
        parentRole.DataTextField = "RoleName";
        parentRole.DataValueField = "RoleId";
        parentRole.DataBind();
        parentRole.Items.Insert(0,new ListItem("无","0"));
    }


    protected void save_Click(object sender, EventArgs e)
    {
        FreeHouse.Model.TRole role = new FreeHouse.Model.TRole();
        role.RoleName = roleName.Text.Trim();
        role.ParentRoleId = 0;//int.Parse(parentRole.SelectedValue);
        role.RoleDescription = Server.HtmlEncode(description.Value);

        if (role.RoleName == "")
        {
            error.Items.Add(new ListItem("填写角色名称"));
        }
        else if (new FreeHouse.BLL.TRole().Exists(role.RoleName))
        {
            error.Items.Add(new ListItem("角色已存在"));
        }
        else
        {
            parentRole.Items.Clear();
            new FreeHouse.BLL.TRole().Add(role);
            error.Items.Add(new ListItem("角色添加成功"));
        }

    }
    protected void back_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}
